import java.lang.annotation.*;
import java.util.Arrays;

public class InheritedAnnotation {
    @Inherited
    @Documented
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface DocumentA {
    }

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface DocumentB {
    }

    @DocumentA
    class A{ }

    class B extends A{ }

    @DocumentB
    class C{ }

    class D extends C{ }

    //测试
    public class DocumentDemo {

        public  void Test(String... args){
            A instanceA=new B();
            System.out.println("已使用的@Inherited注解:"+ Arrays.toString(instanceA.getClass().getAnnotations()));

            C instanceC = new D();

            System.out.println("没有使用的@Inherited注解:"+Arrays.toString(instanceC.getClass().getAnnotations()));
        }
    }
}
